package com.kfm.controller;

import com.kfm.commons.Constant;
import com.kfm.entity.Chat;
import com.kfm.http.HttpExample;
import com.kfm.service.ChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class MessageController {

    @Resource
    private HttpExample httpExample;
    @Autowired
    private ChatService service;

    @RequestMapping("/send")
    public String send(@RequestBody String msg) {
        String result = httpExample.send(msg);
        Chat chat = new Chat();
        chat.setModel("gpt-3.5-turbo");
        chat.setQuestion(msg);
        chat.setAnswer(result);
        service.save(chat);
        return result;
    }


    @GetMapping("/test")
    public String test() {
        Chat chat = new Chat();
        chat.setModel("gpt-3.5-trubo");
        chat.setQuestion("你好");
        chat.setAnswer("你好");
        service.save(chat);
        return "test";
    }
}
